﻿@using KelonProud
@using KelonProud.Mvc.Models
@model KelonProud.Administration.Dtos.UserInputDto

@{
    Layout = "~/Views/Shared/_EditMaster.cshtml";
}

<div class="box from-box modal-box">
    @*<div class="box-header with-border">
            <h3 class="box-title">创建菜单</h3>
        </div>*@
    <form class="form-horizontal" id="EditForm" name="EditForm" validate method="post" role="form">
        @Html.HiddenFor(f => f.Id)
        @Html.HiddenFor(f => f.TenantId)
        <div class="box-body">
            <ul class="nav nav-tabs tab-nav-right" role="tablist">
                <li role="presentation" class="active"><a href="#edit-navigation-details" data-toggle="tab">用户基础信息</a></li>
                <li role="presentation"><a href="#edit-user-roles" data-toggle="tab">关联角色信息</a></li>
            </ul>

            <div class="tab-content">
                <div role="tabpanel" class="tab-pane animated fadeIn active" id="edit-navigation-details">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">用户账号</label>
                        <div class="col-sm-10">
                            @Html.TextBoxFor(f => f.UserName, new { @class = "form-control validate" })
                            <span class="help-block m-b-none">用户账号长度不能小于4个字符且不能超过20个字符，必须填写</span>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">用户姓名</label>
                        <div class="col-sm-10">
                            @Html.TextBoxFor(f => f.Name, new { @class = "form-control validate" })
                            <span class="help-block m-b-none">用户姓名长度不能小于2个字符且不能超过20个字符，必须填写</span>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">电话</label>
                        <div class="col-sm-10">
                            @Html.TextBoxFor(f => f.PhoneNumber, new { @class = "form-control validate", data_inputmask = "'mask': '99999999999'" })
                            <span class="help-block m-b-none">用户绑定的手机号码,，可用于登录、找回密码等功能,必须填写</span>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">邮箱</label>
                        <div class="col-sm-10">
                            @Html.TextBoxFor(f => f.EmailAddress, new { @class = "form-control validate" })
                            <span class="help-block m-b-none">用户绑定邮箱，可用于登录、找回密码等功能</span>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">所属机构</label>
                        <div class="col-sm-10">
                            @Html.Partial("~/Views/Shared/Modals/Components/_DropDownTreeView.cshtml", new DropDownTreeModel
                       {
                           Url = "/api/services/admin/organization/GetOrganzationTree?isHasNull=true",
                           IsMilti = false,
                           Name = "OrganizationUnitId",
                           Value = Model.OrganizationUnitId
                       })
                            <span class="help-block m-b-none">用户所属机构</span>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">启用登录锁定</label>
                        <div class="col-sm-10">
                            <div class="checkbox">
                                @Html.CheckBoxFor(f => f.IsLockoutEnabled, new { @class = "form-control filled-in" })
                                <label for="IsLockoutEnabled" class="form-label col-grey">(若启用，当用户登录失败次数超过系统规定次数，用户账号将被锁定)</label>
                            </div>
                        </div>
                    </div>
                </div>
                <div role="tabpanel" class="tab-pane animated fadeIn" id="edit-user-roles">
                    <div class="row">
                        <div class="col-sm-12 ">
                            @foreach (var role in Model.RoleDtos)
                            {
                                <div class="col-sm-6">
                                    <input type="checkbox" name="role" value="@role.Id" title="@role.Description" class="filled-in" id="@string.Format("role{0}", role.Id)" @(Model.NavIsInRole(role) ? "checked" : "") />
                                    <label for="@string.Format("role{0}", role.Id)" title="@role.DisplayName">@role.DisplayName</label>
                                </div>
                            }
                        </div>
                    </div>
                </div>
            </div>
        </div>
        @Html.Partial("~/Views/Shared/Modals/_ModalFooterWithSaveAndCancel.cshtml")
    </form>
</div>

@section styles {
    <style>
        .menu-ico {
            color: #246f71;
            border-radius: 0;
        }


        .layui-layer-iframe .layui-layer-content {
            height: calc(100% - 100px);
            height: -moz-calc(100% - 100px);
            height: -webkit-calc(100% - 100px);
        }
    </style>
}

@section scripts{
    <script>
        function saveFormEvent(_$form) {
            var _navService = abp.services.admin.user;
            var user = _$form.serializeFormToObject(); //serializeFormToObject is defined in main.js
            user.roleIds = [];
            user.editionIds = [];

            var _$roleCheckboxes = $("input[name='role']:checked");
            if (_$roleCheckboxes) {
                for (var roleIndex = 0; roleIndex < _$roleCheckboxes.length; roleIndex++) {
                    var _$roleCheckbox = $(_$roleCheckboxes[roleIndex]);
                    user.roleIds.push(_$roleCheckbox.val());
                }
            }

            abp.ui.setBusy(_$form);
            _navService.save(user).done(function () {
                if (user.Id === 0) {
                    abp.notify.success("用户创建成功！");
                } else {
                    abp.notify.success("用户修改成功！");
                }

                DiyWindow.closeModal();

            }).always(function () {
                abp.ui.clearBusy(_$form);
            });
        }
    </script>
}